package cn.iocoder.yudao.module.api.pay.transfer.vo;

import cn.iocoder.yudao.module.api.pay.transfer.enums.UnifiedTransferStatusEnum;
import lombok.Data;
import lombok.experimental.Accessors;

import java.time.LocalDateTime;

@Data
@Accessors(chain = true)
public class UnifiedTransferVO {

    /**
     * 转账状态
     *
     * @see UnifiedTransferStatusEnum
     */
    private Integer status;

    /**
     * 统一转账单号
     *
     */
    private String transferNo;

    /**
     * 渠道转账单号
     */
    private String channelTransferNo;

    /**
     * 支付成功时间
     */
    private LocalDateTime successTime;

    /**
     * 原始的返回结果
     */
    private Object rawData;

    /**
     * 调用渠道的错误码
     */
    private String channelErrorCode;
    /**
     * 调用渠道报错时，错误信息
     */
    private String channelErrorMsg;
    /**
     * 渠道 package 信息
     * 特殊：目前只有微信转账有这个东西！！！
     * @see <a href="https://pay.weixin.qq.com/doc/v3/merchant/4012716430">JSAPI 调起用户确认收款</a>
     */
    private String channelPackageInfo;

    /**
     * 创建【WAITING】状态的转账返回
     */
    public static UnifiedTransferVO waitingOf(String transferNo, Object rawData) {
        UnifiedTransferVO vo = new UnifiedTransferVO();
        vo.status = UnifiedTransferStatusEnum.WAITING.getValue();
        vo.transferNo = transferNo;
        vo.rawData = rawData;
        return vo;
    }

    /**
     * 创建【IN_PROGRESS】状态的转账返回
     */
    public static UnifiedTransferVO dealingOf(String channelTransferNo, String transferNo, Object rawData) {
        UnifiedTransferVO vo = new UnifiedTransferVO();
        vo.status = UnifiedTransferStatusEnum.DEALING.getValue();
        vo.channelTransferNo = channelTransferNo;
        vo.transferNo = transferNo;
        vo.rawData = rawData;
        return vo;
    }

    /**
     * 创建【CLOSED】状态的转账返回
     */
    public static UnifiedTransferVO closedOf(String channelErrorCode, String channelErrorMsg, String transferNo, Object rawData) {
        UnifiedTransferVO vo = new UnifiedTransferVO();
        vo.status = UnifiedTransferStatusEnum.CLOSED.getValue();
        vo.channelErrorCode = channelErrorCode;
        vo.channelErrorMsg = channelErrorMsg;
        // 相对通用的字段
        vo.transferNo = transferNo;
        vo.rawData = rawData;
        return vo;
    }

    /**
     * 创建【SUCCESS】状态的转账返回
     */
    public static UnifiedTransferVO successOf(String channelTransferNo, LocalDateTime successTime,
                                              String transferNo, Object rawData) {
        UnifiedTransferVO vo = new UnifiedTransferVO();
        vo.status = UnifiedTransferStatusEnum.SUCCESS.getValue();
        vo.channelTransferNo = channelTransferNo;
        vo.successTime = successTime;
        // 相对通用的字段
        vo.transferNo = transferNo;
        vo.rawData = rawData;
        return vo;
    }

}
